package com.sgl.gk.service.impl;

import com.sgl.common.core.domain.AjaxResult;
import com.sgl.gk.domain.GkStationType;
import com.sgl.gk.mapper.GkStationTypeConfigurationMapper;
import com.sgl.gk.mapper.GkStationTypeEventMapper;
import com.sgl.gk.mapper.GkStationTypeMapper;
import com.sgl.gk.service.GkStationTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author:xec
 * @date:2022/10/31 18:50
 **/
@Service
@Slf4j
public class GkStationTypeServiceImpl implements GkStationTypeService {

    @Autowired
    GkStationTypeMapper gkStationTypeMapper;

    @Autowired
    GkStationTypeConfigurationMapper gkStationTypeConfigurationMapper;

    @Autowired
    GkStationTypeEventMapper gkStationTypeEventMapper;

    @Override
    public List<GkStationType> list(GkStationType gkStationType) {
        List<GkStationType> list = gkStationTypeMapper.list(gkStationType);
        return list;
    }

    @Override
    public AjaxResult add(GkStationType gkStationType) {
        gkStationType.setCreateAt(new Date());
        gkStationType.setLastModifyAt(new Date());
        int row = gkStationTypeMapper.add(gkStationType);
        if (row>0) {
            return AjaxResult.success("插入成功");
        }
        return AjaxResult.error("插入失败");
    }

    @Override
    public AjaxResult edit(GkStationType gkStationType) {
        int row = gkStationTypeMapper.edit(gkStationType);
        if (row>0) {
            return AjaxResult.success("修改成功");
        }
        return AjaxResult.error("修改失败");
    }

    @Transactional
    @Override
    public AjaxResult removeByIds(Long[] ids) {
        int row = gkStationTypeMapper.removeByIds(ids);
        gkStationTypeConfigurationMapper.removeByStationTypeIds(ids);
        gkStationTypeEventMapper.removeByStationTypeIds(ids);
        if (row>0) {
            return AjaxResult.success("删除成功");
        }
        return AjaxResult.error("删除失败");
    }


}
